package com.cskaoyan;

//import com.mysql.jdbc.Driver;

import java.sql.*;

/**
 * 创建日期: 2021/11/23 11:07
 *
 * @author ciggar
 * 查询的Demo
 */
public class JDBCDemo5 {

    public static void main(String[] args) throws SQLException {

        // 1. 注册驱动
//        DriverManager.registerDriver(new Driver());

        // 2. 获取连接  返回的是Connection接口的实现类
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/36th_rev?useSSL=false","root","123456");

        // 3. 获取statement对象 这个对象是用来包装SQL语句为网络请求
        Statement statement = connection.createStatement();

        // 4. 通过statement对象发送SQL语句
        ResultSet resultSet = statement.executeQuery("select * from student");
        // 5. 解析结果集
        while (resultSet.next()) {

            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String aClass = resultSet.getString("class");
            int score = resultSet.getInt("score");

            System.out.println("id:" + id + ", name:" + name +", class:" + aClass + ",score:" + score);

        }

        // 6. 关闭资源
        resultSet.close();
        statement.close();
        connection.close();

    }
}
